﻿using BasicData.Application.Input;
using BasicData.Application.Input.Product;
using BasicData.Application.Output;
using BasicData.Application.Services.Product;
using BasicData.Result;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BasicData.Api.Controllers
{
    /// <summary>
    /// 产品物料
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductController : ControllerBase
    {
        IProductServices services;
        ILogger<ProductController> logger;

        public ProductController(IProductServices services, ILogger<ProductController> logger)
        {
            this.services = services;
            this.logger = logger;
        }
        /// <summary>
        /// 添加产品
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<int> AddProduct(ProductInput input)
        {
            logger.LogInformation("添加产品");
            return services.AddProduct(input);
        }
        /// <summary>
        /// 获取产品列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public ApiPaging<ProductOutput> GetProduct([FromQuery]PageInput input)
        {
            logger.LogInformation("获取产品列表");
            return services.GetProduct(input);
        }
        /// <summary>
        /// 修改产品
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public ApiResult<int> UpdateProduct(UpdateProductInput input)
        {
            logger.LogInformation("修改产品");
            return services.UpdateProduct(input);
        }
        /// <summary>
        /// 删除产品
        /// </summary>
        [HttpPut]
        public ApiResult<int> DeleteProduct(long id)
        {
           logger.LogInformation("删除产品");
            return services.DeleteProduct(id);
        }
    }
}
